<?php
/*
Template Name: Companies Listing
*/

get_header(); ?>

<div id="content">

	<div class="page-template-template-tags-php">

        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

            <div class="hentry-meta">
                <h1>Companies</h1>
            </div>

            <div class="hentry-content clear">
                <div class="tags">
                    <?php
                        /*$tags = get_tags('orderby=name&order=ASC');*/
						$posts = query_posts('cat=12&posts_per_page=-1&orderby=title&order=ASC');
						$cut = ceil( count($posts)/4 ); // number of tags at column
						
                        $capital = '';
                        $i = 0; // iterator
						
                        
                        $cutter = $cut;
                        $letter_i = 0;
                        $output = '<div class="column">';
                        foreach ( $posts as $post ) {
                            $i++;
							//print_r($post); exit;
                            $firstletter = mb_strtolower( mb_substr($post->post_title, 0, 1) );
                            if ( $firstletter !=  $capital ) {
                                $letter_i++;
                                if ( $letter_i != 1 ) $output .= '</ul>';
                                if ( $i > $cutter ) {
                                    $output .= '</div><div class="column">';
                                    $cutter = $cutter + $cut;
                                }
                                $capital = $firstletter;
                                $output .= '<h4>' . $capital . '</h4><ul>';
                            }
                            //$term = get_term_by('id', (int)$post->term_id, 'post_tag');
                            $output .= '<li><a href="javascript:alert(\'men at work\')">' . $post->post_title . '</a> </li>';
                        }
                        echo $output . '</ul></div>';
                    ?>
                </div>
            </div>

        </div> <!-- .page -->


</div>
</div><!-- #content -->

<?php get_sidebar(); ?>

<?php get_footer(); ?>
